home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’96 / VideoFolder 1.0a / Source / MoreFiles 1.4.1 / FileCopy.p < prev    next >
Text File  |  1995-12-21  |  6KB  |  125 lines

  1. UNIT FileCopy;
  2.  
  3. {    Apple Macintosh Developer Technical Support                                }
  4. {                                                                            }
  5. {    FileCopy: A robust, general purpose file copy routine.                    }
  6. {    by Jim Luther, Apple Developer Technical Support Emeritus                }
  7. {                                                                            }
  8. {    File:        FileCopy.p                                                    }
  9. {                                                                            }
  10. {    Copyright © 1992-1995 Apple Computer, Inc.                                }
  11. {    All rights reserved.                                                    }
  12. {                                                                            }
  13. {    You may incorporate this sample code into your applications without        }
  14. {    restriction, though the sample code has been provided "AS IS" and the    }
  15. {    responsibility for its operation is 100% yours.  However, what you are    }
  16. {    not permitted to do is to redistribute the source as "DSC Sample Code"    }
  17. {    after having made changes. If you're going to re-distribute the source,    }
  18. {    we require that you make it clear in the source that the code was        }
  19. {    descended from Apple Sample Code, but that you've made changes.            }
  20.  
  21.  
  22. INTERFACE
  23.  
  24. USES
  25.     Files;
  26.  
  27. {***************************************************************************}
  28.  
  29.  
  30.     FUNCTION FileCopy (srcVRefNum: Integer;
  31.                                     srcDirID: LongInt;
  32.                                     srcName: Str255;
  33.                                     dstVRefNum: Integer;
  34.                                     dstDirID: LongInt;
  35.                                     dstPathname: StringPtr;
  36.                                     copyName: StringPtr;
  37.                                     copyBufferPtr: Ptr;
  38.                                     copyBufferSize: LongInt;
  39.                                     preflight: Boolean): OSErr;
  40. {    Use FileCopy to duplicate a file and optionally rename it.                }
  41. {    Since the PBHCopyFile routine is only available on some                    }
  42. {    AFP server volumes under specific conditions, this routine                }
  43. {    either uses PBHCopyFile, or does all of the work PBHCopyFile            }
  44. {    does.  The srcVRefNum, srcDirID and srcName are used to                    }
  45. {    determine the location of the file to copy.  The dstVRefNum                }
  46. {    dstDirID and dstPathname are used to determine the location of            }
  47. {    the destination directory.  If copyName <> NIL, then it points            }
  48. {    to the name of the new file.  If copyBufferPtr <> NIL, it                }
  49. {    points to a buffer of copyBufferSize that is used to copy                }
  50. {    the file's data.  The larger the supplied buffer, the                    }
  51. {    faster the copy.  If copyBufferPtr = NIL, then this routine                }
  52. {    allocates a buffer in the application heap. If you pass a                }
  53. {    copy buffer to this routine, make its size a multiple of 512            }
  54. {    ($200) bytes for optimum performance.                                    }
  55. {                                                                            }
  56. {    srcVRefNum        input:    Source volume specification.                    }
  57. {    srcDirID        input:    Source directory ID.                            }
  58. {    srcName            input:    Source file name.                                }
  59. {    dstVRefNum        input:    Destination volume specification.                }
  60. {    dstDirID        input:    Destination directory ID.                        }
  61. {    dstPathname        input:    Pointer to destination directory name, or        }
  62. {                            nil when dstDirID specifies a directory.        }
  63. {    copyName        input:    Points to the new file name if the file is        }
  64. {                            to be renamed or nil if the file isn't to        }
  65. {                            be renamed.                                        }
  66. {    copyBufferPtr    input:    Points to a buffer of copyBufferSize that        }
  67. {                            is used the i/o buffer for the copy or            }
  68. {                            nil if you want FileCopy to allocate its        }
  69. {                            own buffer in the application heap.                }
  70. {    copyBufferSize    input:    The size of the buffer pointed to                }
  71. {                            by copyBufferPtr.                                }
  72. {    preflight        input:    If true, FileCopy makes sure there are enough    }
  73. {                            allocation blocks on the destination volume to    }
  74. {                            hold both the data and resource forks before    }
  75. {                            starting the copy.                                }
  76.  
  77.  
  78. {***************************************************************************}
  79.  
  80.  
  81.     FUNCTION FSpFileCopy ({CONST}VAR srcSpec: FSSpec;
  82.                                     {CONST}VAR dstSpec: FSSpec;
  83.                                     copyName: StringPtr;
  84.                                     copyBufferPtr: Ptr;
  85.                                     copyBufferSize: LongInt;
  86.                                     preflight: Boolean): OSErr;
  87. {    Use FSpFileCopy to duplicate a file and optionally rename it.            }
  88. {    Since the PBHCopyFile routine is only available on some                    }
  89. {    AFP server volumes under specific conditions, this routine                }
  90. {    either uses PBHCopyFile, or does all of the work PBHCopyFile            }
  91. {    does.  The srcSpec is used to                                            }
  92. {    determine the location of the file to copy.  The dstSpec is                }
  93. {    used to determine the location of the                                    }
  94. {    destination directory.  If copyName <> NIL, then it points                }
  95. {    to the name of the new file.  If copyBufferPtr <> NIL, it                }
  96. {    points to a buffer of copyBufferSize that is used to copy                }
  97. {    the file's data.  The larger the supplied buffer, the                    }
  98. {    faster the copy.  If copyBufferPtr = NIL, then this routine                }
  99. {    allocates a buffer in the application heap. If you pass a                }
  100. {    copy buffer to this routine, make its size a multiple of 512            }
  101. {    ($200) bytes for optimum performance.                                    }
  102. {                                                                            }
  103. {    srcSpec            input:    An FSSpec record specifying the source file.    }
  104. {    dstSpec            input:    An FSSpec record specifying the destination        }
  105. {                            directory.                                        }
  106. {    copyName        input:    Points to the new file name if the file is        }
  107. {                            to be renamed or nil if the file isn't to        }
  108. {                            be renamed.                                        }
  109. {    copyBufferPtr    input:    Points to a buffer of copyBufferSize that        }
  110. {                            is used the i/o buffer for the copy or            }
  111. {                            nil if you want FileCopy to allocate its        }
  112. {                            own buffer in the application heap.                }
  113. {    copyBufferSize    input:    The size of the buffer pointed to                }
  114. {                            by copyBufferPtr.                                }
  115. {    preflight        input:    If true, FSpFileCopy makes sure there are        }
  116. {                            enough allocation blocks on the destination        }
  117. {                            volume to hold both the data and resource forks    }
  118. {                            before starting the copy.                        }
  119.  
  120.  
  121. {***************************************************************************}
  122.  
  123. IMPLEMENTATION
  124.  
  125. END.